import React,{useState,useRef, useEffect} from 'react'
import { View,Image,Text } from '@tarojs/components'
import Taro,{ useDidShow, useReachBottom } from '@tarojs/taro'

import './index.less'

export default function DetailTransfer() {

  useDidShow(()=>{
    Taro.showLoading({title:"加载中..."})
    const {router} = Taro.getCurrentInstance()
    const orderIdStr= router.params?.id
    if(orderIdStr){
      const orderSourceStr = orderIdStr.length==12?orderIdStr.substring(4,5):orderIdStr.substring(4,6);
      handleToDetail({
        orderSource:orderSourceStr,
        orderId:orderIdStr
      })
    }else{
      Taro.$toast('缺少主要参数')
      setTimeout(() => {
        Taro.redirectTo({
          url:'/orderSubPack/order-list/index'
        })
      }, 1000);
    }
  })

  function handleToDetail(e){   ///  点击详情
    let url = '/orderSubPack/order-list/index'
    if(e.orderSource == 1){
      url = `/orderSubPack/orderDetail/index?orderId=${e.orderId}`;
    }
    if(e.orderSource == 2){
      if(Taro.$channel?.includes('cinema')){
        url = `/mineSubPack/order-detail/index?id=${e.orderId}`
      }
      if(Taro.$channel?.includes('movie')){
        url = `/orderSubPack/cinemaDetail/index?orderId=${e.orderId}`;  /// 玩票详情
      }
    }
    if(e.orderSource == 3){
      url = `/orderSubPack/movieDetail/index?orderId=${e.orderId}`;
    }
    if(e.orderSource == 4){
      url = `/orderSubPack/goodsDetail/index?orderId=${e.orderId}`;
    }
    if(e.orderSource == 6){
      url = `/orderSubPack/powerDetail/index?orderId=${e.orderId}`;
    }
    if(e.orderSource == 11){
      url = `/mineSubPack/food-detail/index?id=${e.orderId}`
    }
    if(e.orderSource == 5 || e.orderSource == 9 || e.orderSource == 8){
      url = `/orderSubPack/card-detail/index?orderId=${e.orderId}&type=${e.orderSource}`;
    }
    if(e.isOpenOrder){
      url = `/orderSubPack/activityDetail/index?orderId=${e.orderId}`;
    }
    Taro.redirectTo({
      url
    })
  }
  
  return (
    <View className="detail-transfer"></View>
  )
}
